package com.netscenery.util;

public class QName {
	private  String prefix;
	private  String localName;
	
	public QName(String qName){
		parseQName(qName);
	}
	
	public QName(String prefix, String localName){
		this.prefix = prefix;
		this.localName = localName;
	}
	
	public void parseQName( String qName){
		if (null == qName){
			return;
		}
		if(!qName.contains(":")){
			localName = qName;
			prefix = null;
			return;
		}
		
		int sepPos = qName.indexOf(":");
		prefix = qName.substring(0,sepPos);
		localName = qName.substring(sepPos + 1);
	}

	/**
	 * @return the prefix
	 */
	public String getPrefix() {
		return prefix;
	}

	/**
	 * @param prefix the prefix to set
	 */
	public void setPrefix(String prefix) {
		this.prefix = prefix;
	}

	/**
	 * @return the localName
	 */
	public String getLocalName() {
		return localName;
	}

	/**
	 * @param localName the localName to set
	 */
	public void setLocalName(String localName) {
		this.localName = localName;
	}
	
	public String toString(){
		StringBuffer sb  = null;
		if (null != prefix){
			sb = new StringBuffer(prefix);
			sb.append(":");
		}
		
		if (null == sb){
			sb = new StringBuffer(localName);
		}
		else {
			sb.append(localName);
		}
		
		return sb.toString();
	}
	
	public boolean isQName(){
		if (null != prefix){
			return true;
		}
		return false;
	}
	
	
}
